<template>
	<view>
		<view class="mainpadding_top">
			<view class="margin_top flexcolumn" v-if="pay_type==30">
				<view class="titletext hei_text bold">实付积分</view>
				<view class="margin_top6 hei_text bold" style="font-size: 60rpx;">{{pay_score}}</view>
			</view>
			<view class="margin_top flexcolumn" v-if="pay_type!=30">
				<view class="titletext hei_text bold">实付金额</view>
				<view class="margin_top6 hei_text bold" style="font-size: 60rpx;">{{pay_price}}</view>
			</view>
			<view class="mainpadding_top  margin_top6 ffffff radius">
				<view class="flexbetween" @click="pay_type=10">
					<view class="flexleft">
						<u-icon name="weixin-circle-fill" color="#26db6f" size="28"></u-icon>
						<view class="titletext hei_text margin_left">微信</view>
					</view>
					<u-icon name="checkmark-circle-fill" v-show="pay_type==10" color="#ff8505" size="24"></u-icon>
					<u-icon name="checkmark-circle-fill" v-show="pay_type!=10" color="#999" size="24"></u-icon>
				</view>
				<view class="margin_top5 flexbetween" @click="pay_type=20">
					<view class="flexleft">
						<u-icon name="zhifubao-circle-fill" color="#55aaff" size="28"></u-icon>
						<view class="titletext hei_text margin_left">支付宝</view>
					</view>
					<u-icon name="checkmark-circle-fill" v-show="pay_type==20" color="#ff8505" size="24"></u-icon>
					<u-icon name="checkmark-circle-fill" v-show="pay_type!=20" color="#999" size="24"></u-icon>
				</view>
				<view class="margin_top5 flexbetween" @click="pay_type=30">
					<view class="flexleft">
						<image class="iconclass " src="../static/images/system/score.png" mode=""></image>
						<view class="titletext hei_text margin_left">积分（可用{{userInfo.score}}）</view>
					</view>
					<u-icon name="checkmark-circle-fill" v-show="pay_type==30" color="#ff8505" size="24"></u-icon>
					<u-icon name="checkmark-circle-fill" v-show="pay_type!=30" color="#999" size="24"></u-icon>
				</view>
			</view>

		</view>
		<view class="mainpadding gudingdb">
			<view class="bigbtn" @click="submit()">立即支付</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				pay_price: "",
				pay_score: "",
				type: 1, //1租买车支付，2酒店支付,3车辆养护，4餐饮
				userInfo: {},
				order_id: "",
				pay_type: 10
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.pay_price = data.pay_price
			this.type = data.type
			this.order_id = data.order_id
			this.pay_score = data.pay_score
			this.init()
		},
		methods: {
			init() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			submit() {
				if (this.pay_type == 30) {
					if (Number(this.userInfo.score) < Number(this.pay_score)) {
						httpRequest.toast("可用积分不足")
						return false
					}
				}
				let url = "/api/carordercl/payment"//租买车支付
				if (this.type == 2) {//酒店支付
					url='/api/Hotelordercl/payment'
				}
				if (this.type == 3) {//车辆养护
					url='/api/Carshopordercl/payment'
				}
				if (this.type == 4) {//餐饮
					url='/api/Foodshoporder/payment'
				}
				httpRequest.request(url, 'POST', {
					pay_type: this.pay_type,
					order_id: this.order_id
				}).then(res => {
					if (res.code == 1) {
						if (this.pay_type == 10) { //微信
							uni.requestPayment({
								provider: 'wxpay',
								orderInfo: res.data.appconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						} else if (this.pay_type == 20) { //支付宝
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.appconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						} else {
							httpRequest.toast(res.msg)
							setTimeout(() => {
								uni.navigateBack(1)
							}, 1000)
						}
					} else {
						httpRequest.toast(res.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.iconclass {
		width: 45rpx;
		height: 45rpx;
	}
</style>